<%--
@author Kusal Samarakoon
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>

<script type="text/javascript">

    $(document).ready(function () {
        $('.land-table').dataTable({
            "sPaginationType":"full_numbers",
            "bDestroy":true,
            "oLanguage":{
                "sZeroRecords":$('#no-record').val(),
                "sLengthMenu":$('#display').val() + " _MENU_ " + $('#records').val(),
                "sSearch":$('#search').val(),
                "sInfo":$('#showing').val() + " _START_ " + $('#to').val() + " _END_ " + $('#of').val() + " _TOTAL_ " + $('#entries').val(),
                "sInfoEmpty":$('#no-record').val(),
                "oPaginate":{
                    "sFirst":$('#first').val(),
                    "sLast":$('#last').val(),
                    "sNext":$('#next').val(),
                    "sPrevious":$('#previous').val()
                }
            },
            "fnDrawCallback":function () {
                if ($('.dataTables_paginate span span.paginate_button').size()) {
                    $('.dataTables_paginate')[0].style.display = "block";
                } else {
                    $('.dataTables_paginate')[0].style.display = "none";
                }
            }
        });

        //Onclick View link
        /*    $('#viewLink').click(function () {

         });  */

    });

    $(function() {


        $('select#district').bind('change', function(evt1) {
            var id = $("select#district").attr("value");
            $.getJSON('${pageContext.request.contextPath}/common/DivisionLookupService', {id:id,mode:2},
                     function(data) {
                         var options1 = '<option value="0"> - Select  - </option> ';
                         var ds = data.dsDivisionList;
                         for (var i = 0; i < ds.length; i++) {
                             options1 += '<option value="' + ds[i].optionValue + '">' + ds[i].optionDisplay + '</option>'

                         }
                         $("select#dsDivision").html(options1);
                     });

        });
    });


    /*function loadLands() {

     var id = $("select#dsDivision").attr("value");
     var mode = "search";
     var type = "searchApprovedLandsbyDS";

     $.getJSON('${pageContext.request.contextPath}/common/LandLookupService', {id:id, mode:mode, type:type}, function(data) {
     loadLandList(data.landList);
     });
     }*/


    function viewLandDetails(landId) {
        //alert(landId);
        //ajax find land list by parent id
        var url = '${"findClildrenByParentLand.do?landId=' + landId + '"}';
        $.get(url, $(this).serialize(), function(data) {
            $("#landDetails").html(data);
            //if list contain only one element display land details
            //else
            //display in tree
        });
    }


</script>

<div id="land-registration-module-home-title" class="module-home-title">
    <s:a href="searchModule.do"><img src="${pageContext.request.contextPath}/images/search.png"
                                     alt="Land Alienation"><span><s:label
            value="%{getText('search.label')}"/></span></s:a>
    <span class="module-title-breaker"> > </span>
    <s:a href="searchLandsUpperLevel.do"><img
            src="${pageContext.request.contextPath}/images/searchLand.png"><span><s:label
            value="%{getText('search_lands.label')}"/></span></s:a>
    <div id="back-button" align="right">
            <s:form><s:submit value="%{getText('back_btn.label')}" action="searchModule"/></s:form>
        </div>
</div>

<div class="page-title">
    <h2><s:label value="%{getText('search_lands.label')}"/></h2>
</div>
<div id="search-lands-form-outer">

    <table>


        <tr>
            <s:form name="searchLandByDSUpperLevel" id="searchLandByLandName" method="POST">

                <td class="left-align"><s:label value="%{getText('district.label')}"/></td>
                <td><s:select list="districtList" name="districtId" headerKey="0" headerValue="-- Select --"
                              id="district"/></td>


                <td class="left-align"><s:label value="%{getText('ds_division.label')}"/></td>
                <td><s:select name="dsDivisionId" id="dsDivision" headerKey="0" headerValue="-- Select --"
                              list="dsDivisionList" cssClass="width-180-px"/>
                </td>

                <td><s:submit action="searchLandByDSUpperLevel" value="%{getText('search.label')}"/></td>
            </s:form>

        </tr>
    </table>

    <table>
        <tr>
            <s:form name="searchLandByLandNameUpperLevel" id="searchLandByLandName" method="POST">
                <td><s:label value="%{getText('name_of_land.label')}"/></td>
                <td><s:textfield name="searchText" id="searchTextLandName"/></td>
                <td><s:submit action="searchLandByLandNameUpperLevel" value="%{getText('search.label')}"/></td>
                <s:hidden name="searchType" value="1"/>
            </s:form>

        </tr>
        <tr>
            <s:form name="searchLandByPlanNoUpperLevel" id="searchLandByPlanNo" method="POST">
                <td><s:label value="%{getText('plan_no.label')}"/></td>
                <td><s:textfield name="searchText" id="searchTextPlanNo"/></td>
                <td><s:submit action="searchLandByPlanNoUpperLevel" value="%{getText('search.label')}"/></td>
                <s:hidden name="searchType" value="2"/>
            </s:form>
        </tr>
        <tr>
            <s:form name="searchLandByLotNoUpperLevel" id="searchLandByLotNo" method="POST">
                <td><s:label value="%{getText('lot_no.label')}"/></td>
                <td><s:textfield name="searchText" id="searchTextLotNo"/></td>
                <td><s:submit action="searchLandByLotNoUpperLevel" value="%{getText('search.label')}"/></td>
                <s:hidden name="searchType" value="3"/>
            </s:form>
        </tr>
        <tr>
            <s:form name="searchLandByHolderNameUpperLevel" id="searchLandByHolderName" method="POST">
                <td><s:label value="%{getText('holder_name.label')}"/></td>
                <td><s:textfield name="searchText" id="searchTextHolderName"/></td>
                <td><s:submit action="searchLandByHolderNameUpperLevel" value="%{getText('search.label')}"/></td>
                <s:hidden name="searchType" value="4"/>
            </s:form>
        </tr>
    </table>
</div>

<%--<div id="land-list">
    <table class="width-100 margin-10-auto table land-table">

    </table>
</div>--%>

<table id="land-table" class="width-100 margin-10-auto table land-table">
    <thead>
    <tr>
        <th><s:label value="%{getText('slmsSerialNumber.label')}"/></th>
        <th><s:label value="%{getText('name_of_the_land.label')}"/></th>
        <th><s:label value="%{getText('gn_division.label')}"/></th>
        <th><s:label value="%{getText('plan_no.label')}"/></th>
        <th><s:label value="%{getText('lot_no.label')}"/></th>
        <th><s:label value="%{getText('alienation_status.label')}"/></th>
        <th><s:label value="%{getText('action.label')}"/></th>
    </tr>
    </thead>
    <tbody>
    <s:iterator status="lands" value="landList">

        <tr>
            <%--<td width="130px"><s:if test="referenceNumber > 0"><s:property
                    value="referenceNumber"/></s:if><s:else><s:label
                    value="%{getText('undefined.label')}"/></s:else></td>--%>
            <td width="80px"><s:property value="id"/></td>
            <td><s:property value="nameOfTheLand"/></td>
            <td><s:property value="gnDivision.enDivisionName"/></td>
            <td width="80px"><s:property value="planNumber"/></td>
            <td width="80px"><s:property value="lotNumber"/></td>
            <td width="180px"><s:property value="alienationState"/></td>
            <td width="80px" class="center-align">
                <a href="#" title="View" id="viewLink" onclick="viewLandDetails('<s:property value="id"/>')">
                    <img src="${pageContext.request.contextPath}/images/detailed-form.png" style="border:none; width:25px; height:25px;"/> </a>

            </td>
        </tr>

    </s:iterator>
    </tbody>
</table>

<div id="landDetails">

</div>


<%-- Localization text for java script generated text --%>
<s:hidden id="ref" value="%{getText('reference_no.label')}"/>
<s:hidden id="lname" value="%{getText('name_of_the_land.label')}"/>
<s:hidden id="plan" value="%{getText('plan_no.label')}"/>
<s:hidden id="lot" value="%{getText('lot_no.label')}"/>
<s:hidden id="action" value="%{getText('action.label')}"/>
<s:hidden id="viewTooltip" value="%{getText('view_tooltip.label')}"/>
<s:hidden id="undifined" value="%{getText('undefined.label')}"/>

<%-- Localization text for data tables --%>
<s:hidden id="display" value="%{getText('display.label')}"/>
<s:hidden id="records" value="%{getText('records.label')}"/>
<s:hidden id="search" value="%{getText('search.label')}"/>
<s:hidden id="no-record" value="%{getText('no_record.label')}"/>
<s:hidden id="showing" value="%{getText('showing.label')}"/>
<s:hidden id="to" value="%{getText('to.label')}"/>
<s:hidden id="of" value="%{getText('of.label')}"/>
<s:hidden id="entries" value="%{getText('entries.label')}"/>
<s:hidden id="first" value="%{getText('first.label')}"/>
<s:hidden id="last" value="%{getText('last.label')}"/>
<s:hidden id="next" value="%{getText('next.label')}"/>
<s:hidden id="previous" value="%{getText('previous.label')}"/>



